/*
 * Copyright 2008 Lucas Tan.
 * This copyright notice must always remain intact whenever you use or distribute 
 * the source code contained in this file.
 * Any usage of any code in this file, either in derived work or
 * through the use of external linkage,
 * must always be credited with the author's name.
 * 
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 * DEALINGS IN THE SOFTWARE.
 * 
 * */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace PassKeeper.Gui
{
	public partial class ExceptionBox : Form
	{
		public ExceptionBox()
		{
			InitializeComponent();
		}

		public static void Show(IWin32Window owner, string message,Exception e )
		{
			if (e == null)
			{
				throw new ArgumentNullException("e");
			}
			if (message == null)
			{
				throw new ArgumentNullException("message");
			}

			ExceptionBox box = new ExceptionBox();

			box.lblText.Text = Util.FormatResourceString(
				"Exception_Occurred",
				e.GetType().Name, 
				message
			);

			box.txtDetails.Text = e.ToString();

			box.Text = Util.GetResourceString("Error_Message_Caption");

			if (owner != null)
			{
				box.Show(owner);
			}
			else
			{
				box.Show();
			}
		}

		private void ExceptionBox_Load(object sender, EventArgs e)
		{
			this.btnOK.Focus();
		}

		private void ExceptionBox_StyleChanged(object sender, EventArgs e)
		{
			Util.SetFont(this);
		}

		private void btnOK_Click(object sender, EventArgs e)
		{
			this.Close();
		}
	}
}